# build release version of testbed app

# external control variables:
#
# GLEW_INC_PATH							-- path to GLEW includes
# GLEW_LIB_PATH							-- path to GLEW binaries
# L3DS_INC_PATH							-- path to lib3ds includes
# L3DS_LIB_PATH							-- path to lib3ds binaries
# HOSTTYPE								-- same as shell's HOSTTYPE

TARGETS = testbed

UNAME := $(shell uname)

SRCS = main.cpp rendCameraVisual.cpp rendBoxVisual.cpp rendColor.cpp rendMaterial.cpp rendRegister.cpp rendCamera.cpp rendLight.cpp rendAttrBuffer.cpp rendAttrBufferMapped.cpp rendMesh.cpp rendSystem.cpp rendSkeleton.cpp
OBJS = $(SRCS:.cpp=.o)

CC = g++
CFLAGS += -pipe -fmessage-length=0 -fno-rtti -O3 -funroll-loops -ffast-math -fstrict-aliasing -Wtrigraphs -Wreturn-type -Wunused-variable -Wunused-value -DNDEBUG
#CFLAGS += -pipe -fmessage-length=0 -fno-rtti -O0 -g -ffast-math -fstrict-aliasing -Wtrigraphs -Wreturn-type -Wunused-variable -Wunused-value -DDEBUG

ifdef GLEW_INC_PATH
	CFLAGS += -I"$(GLEW_INC_PATH)"
endif
ifdef GLEW_LIB_PATH
	CLINKFLAGS += -L"$(GLEW_LIB_PATH)"
endif

ifdef L3DS_INC_PATH
	CFLAGS += -I"$(L3DS_INC_PATH)"
endif
ifdef L3DS_LIB_PATH
	CLINKFLAGS += -L"$(L3DS_LIB_PATH)"
endif

ifeq ($(UNAME), Darwin)

	# here we provide the main point of differentiation between ppc (G4, ATI 9200) and intel macs
	ifeq ($(HOSTTYPE), powerpc)
		CFLAGS += -arch ppc -mtune=7450 -faltivec -DUSE_ATI_FRAGMENT_SHADER
		CLINKFLAGS += -framework GLUT -framework OpenGL -framework CoreServices -arch ppc -Wl,-Y,1455
	else
		ifeq ($(HOSTTYPE), x86_64)
			CFLAGS += -arch x86_64 -mfpmath=sse
			CLINKFLAGS += -framework GLUT -framework OpenGL -framework CoreServices -arch x86_64 -Wl,-Y,1455
		else
			CFLAGS += -arch i386 -msse3 -mfpmath=sse
			CLINKFLAGS += -framework GLUT -framework OpenGL -framework CoreServices -arch i386 -Wl,-Y,1455
		endif
	endif

else

	CLINKFLAGS += -lGLEW -lrt

	ifeq ($(findstring CYGWIN, $(UNAME)), CYGWIN)
		CFLAGS += -D_WIN32
		CLINKFLAGS += -lglut32 -lopengl32
		EXE = .exe
	else
		CLINKFLAGS += -lglut -lGLU -lGL
	endif

	ifeq ($(HOSTTYPE), powerpc)
		CFLAGS += -D__ppc__
	endif

endif

CLINKFLAGS += -l3ds -lstdc++

CXXFLAGS = $(CFLAGS)
CXXLINKFLAGS = $(CLINKFLAGS)

BINARIES := $(TARGETS:=$(EXE))

all: $(BINARIES)

$(BINARIES) : $(OBJS)
	$(CC) -o $@ $(OBJS) $(CLINKFLAGS)

clean:
	$(RM) $(BINARIES) $(OBJS)

clobber: clean
	$(RM) *.bak *~

.PHONY: all clean clobber

